var  current_array = [], inflow_array = [], outflow_array = [], time_gap = [];
for(var i=0;i<24;i++){
    for(var j =0;j<12;j++){
        var hour = i<10?('0'+i):(i+'');
        var minute = (j*5)<10?('0'+j*5+''):(j*5+'');
        var time = hour + ':'+ minute;
        time_gap.push(time);
        current_array.push(0);
        inflow_array.push(0);
        outflow_array.push(0);
    }
}
var HeatChartAreaName = {
    '12925':{name:'1号馆',path:[[113.385589,22.016881],[113.386130142857,22.0173965714286],[113.387012142857,22.0166298571429],[113.386475,22.016119],[113.385589,22.016881]]},
    '12926':{name:'2号馆',path:[[113.386130142857,22.0173965714286],[113.386671285714,22.0179121428571],[113.387549285714,22.0171407142857],[113.387012142857,22.0166298571429],[113.386130142857,22.0173965714286]]},
    '12928':{name:'3号馆',path:[[113.386671285714,22.0179121428571],[113.387212428571,22.0184277142857],[113.388086428571,22.0176515714286],[113.387549285714,22.0171407142857],[113.386671285714,22.0179121428571]]},
    '12929':{name:'4号馆',path:[[113.387212428571,22.0184277142857],[113.387753571429,22.0189432857143],[113.388623571429,22.0181624285714],[113.388086428571,22.0176515714286],[113.387212428571,22.0184277142857]]},
    '12930':{name:'5号馆',path:[[113.387753571429,22.0189432857143],[113.388294714286,22.0194588571429],[113.389160714286,22.0186732857143],[113.388623571429,22.0181624285714],[113.387753571429,22.0189432857143]]},
    '12931':{name:'6号馆',path:[[113.388294714286,22.0194588571429],[113.388835857143,22.0199744285714],[113.389697857143,22.0191841428571],[113.389160714286,22.0186732857143],[113.388294714286,22.0194588571429]]},
    '12932':{name:'7号馆',path:[[113.388835857143,22.0199744285714],[113.389377,22.02049],[113.390235,22.019695],[113.389697857143,22.0191841428571],[113.388835857143,22.0199744285714]]},
    '12933':{name:'8号馆',path:[[113.385792,22.018637],[113.386291,22.018169],[113.385175,22.017155],[113.384666,22.017602],[113.384666,22.017602]]},
    '12934':{name:'10号馆',path:[[113.383711,22.017065],[113.38281,22.016389],[113.383561,22.015673],[113.384441,22.016399]]},
    '12935':{name:'安检入口',path:[[113.382772,22.015693],[113.382558,22.015941],[113.381835,22.015446],[113.382069,22.015195]]},
    '12936':{name:'餐厅B',path:[[113.392333,22.02065],[113.393561,22.019298],[113.39208,22.018109],[113.390793,22.019526],[113.390793,22.019526]]},
    '12937':{name:'P1停车场',path:[[113.380774,22.014722],[113.382491,22.016053],[113.382222,22.016247],[113.378049,22.013005],[113.378049,22.013005],[113.378301,22.012798],[113.379814,22.011186],[113.382174,22.013225]]},
    '12954':{name:'P2停车场',path:[[113.394665,22.02578],[113.397594,22.022503],[113.393989,22.019484],[113.393481,22.020343],[113.393481,22.020343],[113.394468,22.021072],[113.392162,22.023877]]},
    '12939':{name:'航展馆南',path:[[113.382496,22.013078],[113.385285,22.010532],[113.382839,22.008224],[113.380028,22.010909]]},
    '12940':{name:'静展区',path:[[113.390539,22.019737],[113.392763,22.017484],[113.388751,22.013714],[113.386283,22.015674]]},
    '12941':{name:'新闻中心',path:[[113.39092,22.022895],[113.389087,22.02154],[113.389924,22.02051],[113.391736,22.02182]]},
    '12942':{name:'装备展示区',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12970':{name:'航展馆',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12867':{name:'1号线-香洲公交总站',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12863':{name:'2号线-珠海体育中心东门',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12869':{name:'3号线-九洲城',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12868':{name:'4号线-九洲港',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12874':{name:'5号线-城轨珠海站',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12862':{name:'6号线-前山枢纽站',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12870':{name:'7号线-华发商都',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12866':{name:'8号线-斗门汽车客运站',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12864':{name:'9号线-国际赛车场',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12969':{name:'10号线-港珠澳大桥珠海口岸',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12967':{name:'P1公共巴士停车场',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12966':{name:'P2公共巴士停车场',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12965':{name:'P3公共巴士停车场',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12964':{name:'P4公共巴士停车场',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12963':{name:'P5中航通飞',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12962':{name:'P6银隆',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12968':{name:'P7西部新城B片区',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12961':{name:'P8乾务',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12865':{name:'P9金台寺',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12861':{name:'城轨珠海北站',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12859':{name:'江珠高速出入口',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12860':{name:'下栅出入口',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12873':{name:'银隆公司',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12872':{name:'中航通飞',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
    '12857':{name:'105上冲路口',path:[[113.385865,22.015704],[113.388633,22.013635],[113.385543,22.01075],[113.382861,22.013038]]},
};
airPassengerFlow = {
    flowChart: null,
    positionChart:null,
    heatChart:null,
    heatMap:null,
    heat_polygon:{},
    heat_init:false,
    heat_marker:{},
    infoWindow:null,
    init: function () {
        initArea();
        initEchart1Data();
        initEchart2Data();
        initHeatChart();
    },
    // center:[113.385441,22.013558],
    center: [113.387424,22.016773]
};

// 客流图表
var initEchart1Data = function () {
    airPassengerFlow.flowChart = echarts.init(document.getElementById('flow_chart'));
    airPassengerFlow.flowChart.setOption(getEchart1Option());
    setInterval(function () {
        airPassengerFlow.flowChart.setOption(getEchart1Option());
    }, 1000 * 60 * 5)
}
var getEchart1Option = function () {
    $.ajax({
        url: "getUserCounts.do",
        type: "GET",
        async: false,
        success: function (result) {
            var resultMap = result.data;
            for (var r in resultMap) {
                var index = time_gap.indexOf(resultMap[r].key.substr(0,5));
                current_array[index]=resultMap[r].value.userCount;
            }
        }
    });

    $.ajax({
        url: "getUserFlowCounts.do",
        type: "GET",
        async: false,
        success: function (result) {
            var flowList = result.data;
            for (var f in flowList) {
                if (time_gap.indexOf(f.substr(0,5))>-1) {
                    var index = time_gap.indexOf(f.substr(0,5));
                    inflow_array[index] = flowList[f].userInflowCount;
                    outflow_array[index] = flowList[f].userOutflowCount;
                }
            }
        }
    });


    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                shadowStyle: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: 'rgba(255,255,255,.1)'},
                            {offset: 1, color: 'rgba(255,255,255,0)'}
                        ], false)
                }
            },
            formatter: function (a) {
                var tipHtml = '<div class="chart-tip"><span>' + a[0].axisValue + '</span>';
                for (var i = 0; i < a.length; i++) {
                    tipHtml += '<p>' + a[i].seriesName + '： ' + a[i].value + ' 人</p>';
                }
                tipHtml += '</div>';
                return tipHtml
            },
            backgroundColor: 'transparent',
            padding: 0
        },
        legend: {
            show: false
        },
        grid: {
            show: true,
            left: 0,
            right: 0,
            bottom: 0,
            top: 10,
            containLabel: true,
            backgroundColor: 'rgba(0,0,0,0.2)',
            borderWidth: 0
        },
        xAxis: {
            type: 'category',
            // data: ['07:00', '07:30', '08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00',
            //     '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00', '19:30', '20:00',
            // ],
            data: time_gap,
            axisTick: {
                show: false
            },
            axisLabel: {
                fontSize: 14,
                color: '#ffffff'
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: '#236386'
                }
            },
            splitLine: {
                show: false
            }

        },
        yAxis: {
            type: 'value',
            axisTick: {
                show: false
            },
            axisLabel: {
                fontSize: 12,
                color: '#95a9bb'
            },
            axisLine: {
                show: false
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#236386'
                }
            }
        },
        series: [{
            name: '馆内客流',
            type: 'line',
            data: current_array,
            areaStyle: {
                color: '#fff79c',
                opacity: 0.5
            },
            symbolSize: 5,
            itemStyle: {
                opacity: 0 ,
            },
            emphasis:{
                itemStyle:{
                    color: '#ffffff',
                    borderColor: '#fff79c',
                    borderWidth: 2,
                    opacity: 1
                }
            },
            lineStyle: {
                color: '#fff79c',
                width: 2
            },
            zlevel: 10
        },
            {
                name: '入场客流',
                type: 'line',
                // data: [28, 50, 68, 50, 35, 25, 10, 5, 0, 0, 0, 0, 0, 10, 20, 10, 0, 30, 20, 28, 10, 5, 0, 0, 0],
                data: inflow_array,
                itemStyle: {
                    color: '#fff',
                    borderColor: '#fff',
                    borderWidth: 2,
                    opacity: 0
                },
                lineStyle: {
                    color: '#fff',
                    width: 2
                },
                zlevel: 30
            },
            {
                name: '离场客流',
                type: 'line',
                // data: [10, 15, 8, 9, 12, 10, 8, 7, 15, 0, 10, 15, 13, 20, 10, 15, 12, 15, 13, 12, 15, 10, 15, 8, 4, 2, 5],
                data: outflow_array,
                itemStyle: {
                    color: '#f96322',
                    borderColor: '#f96322',
                    borderWidth: 2,
                    opacity: 0
                },
                lineStyle: {
                    color: '#f96322',
                    width: 2
                },
                zlevel: 20
            }
        ]
    };
    console.log(option);
    return option;
};

// 位置分布图表
var initEchart2Data = function () {
    airPassengerFlow.positionChart = echarts.init(document.getElementById('positionChart'));
    airPassengerFlow.positionChart.setOption(getEchart2Option());
    setInterval(function () {
        airPassengerFlow.positionChart.setOption(getEchart2Option());
    }, 1000 * 60 * 5)
}
//todo 地区分布
var distributionDataName = {
    '珠海':{name:'珠海市'},
    '广州':{name:'广州市'},
    '江门':{name:'江门市'},
    '佛山':{name:'佛山市'},
    '顺德':{name:'顺德市'},
    '肇庆':{name:'肇庆市'},
    '惠州':{name:'惠州市'},
    '阳江':{name:'阳江市'}
}
var getEchart2Option = function () {
    var distributionData = [];
    $.ajax({
        url:"getDistributionData.do",
        type:"GET",
        async:false,
        success:function (data) {
            var result = data.data;
            var other = {name:'其他',value:0};
            for(var r in result){
                if(distributionDataName[result[r].originName]) {
                    distributionData.push({name: result[r].originName, value: result[r].userCount});
                }else {
                    other.value += result[r].userCount;
                }
            }
            distributionData.push(other);
        }
    })
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: function (a) {
                var tipHtml = '<div class="chart-tip">' +
                    '<span>' + a.name + '</span>' +
                    '<p>' + a.value + ' 人</p>' +
                    '</div>';
                return tipHtml
            },
            backgroundColor: 'transparent',
            padding: 0
        },
        color:[
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#00cf8d'},
                    {offset: 1, color: '#15bc87'}
                ], false),
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#b6a2de'},
                    {offset: 1, color: '#af93e7'}
                ], false),
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#5ab1ef'},
                    {offset: 1, color: '#399fe7'}
                ], false),
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#ffb980'},
                    {offset: 1, color: '#f4a362'}
                ], false),
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#d87a80'},
                    {offset: 1, color: '#df626a'}
                ], false),
            new echarts.graphic.LinearGradient(
                1, 0, 0, 0,
                [
                    {offset: 0, color: '#8d98b3'},
                    {offset: 1, color: '#7888b0'}
                ], false)
        ],
        series: [{
            type: 'treemap',
            left: 0,
            top: 0,
            right: 0,
            bottom: 0,
            data:distributionData,
            // data: [{
            //     name: '珠海市',
            //     value: 65536
            // }, {
            //     name: '金湾区',
            //     value: 48747
            // }, {
            //     name: '广州市',
            //     value: 14423
            // }, {
            //     name: '香洲区',
            //     value: 12236
            // }, {
            //     name: '斗门区',
            //     value: 4288
            // }, {
            //     name: '中山市',
            //     value: 3111
            // }],
            label: {
                position: 'insideLeft',
                formatter: function (params) {
                    var arr = [
                        '{name|' + params.name + '}',
                        '{value|' + echarts.format.addCommas(params.value) + '人}'
                    ];
                    return arr.join('\n');
                },
                rich: {
                    name: {
                        fontSize: 16,
                        lineHeight: 26,
                        color: '#fff'
                    },
                    value: {
                        fontSize: 14,
                        color: '#fff'
                    }
                },
                offset: [4, 0],
                textShadowColor: 'rgba(0,0,0,0.2)',
                textShadowBlur: 1,
                textShadowOffsetY: 1
            },
            breadcrumb: {
                show: false
            },
            itemStyle: {
                gapWidth: 1,
                borderColor: 'transparent'
            }
        }]
    };
    return option;
};
var HeatChartName ={
    '1':'唐家镇',
    '2':'金鼎镇',
    '3':'淇澳镇',
    '4':'万山海洋开发试验区',
    '5': '前山街道办',
    '6':'香湾街道办',
    '7': '狮山街道办',
    '8': '梅华街道办',
    '9':  '翠香街道办',
    '10':  '拱北街道办',
    '11':  '吉大街道办',
    '12':  '南屏街道办',
    '13':  '湾仔街道办',
    '14':  '红旗镇',
    '15':  '三灶镇',
    '16':  '平沙镇',
    '17':  '南水镇',
    '18':  '高栏港区',
    '19':  '井岸镇',
    '20':  '白藤湖街道办',
    '21':  '白蕉镇',
    '22':  '斗门镇',
    '23':  '乾务镇',
    '24':  '莲溪镇',
    '25':  '横琴新区',
}
/*
var HeatChartName = {
    '12857': {name: "105上冲路口", lon: 113.513945, lat: 22.281529, count: 0},
    '12859': {name: "江珠高速出入口", lon: 113.392758, lat: 22.17667, count: 0},
    '12860': {name: "下栅出入口", lon: 113.540804, lat: 22.422177, count: 0},
    '12861': {name: "城轨珠海北站", lon: 113.558433, lat: 22.406864, count: 0},
    '12862': {name: "前山枢纽站", lon: 113.531747, lat: 22.24058, count: 0},
    '12863': {name: "体育中心", lon: 113.542861, lat: 22.279685, count: 0},
    '12864': {name: "珠海国际赛车场", lon: 113.568307, lat: 22.370494, count: 0},
    '12865': {name: "金台寺", lon: 113.23605, lat: 22.230332, count: 0},
    '12866': {name: "斗门汽车客运站", lon: 113.315788, lat: 22.233848, count: 0},
    '12867': {name: "香洲公交总站", lon: 113.566838, lat: 22.27971, count: 0},
    '12868': {name: "九洲港码头", lon: 113.598634, lat: 22.24524, count: 0},
    '12869': {name: "九洲城", lon: 113.585755, lat: 22.262261, count: 0},
    '12870': {name: "华发商都", lon: 113.517393, lat: 22.230704, count: 0},
    '12872': {name: "中航通飞", lon: 113.378178, lat: 22.007422, count: 0},
    '12873': {name: "银隆公司", lon: 113.374262, lat: 22.081156, count: 0},
    '12874': {name: "城轨珠海站", lon: 113.55616, lat: 22.221198, count: 0}
}
// todo 热力图area_id  对应经纬度
var HeatChart = [
    {"lng": 113.513945, "lat": 22.281529, "count": 0, 'area_id': '12857'},
    {"lng": 113.392758, "lat": 22.17667, "count": 0, 'area_id': '12859'},
    {"lng": 113.540804, "lat": 22.422177, "count": 0, 'area_id': '12860'},
    {"lng": 113.558433, "lat": 22.406864, "count": 0, 'area_id': '12861'},
    {"lng": 113.531747, "lat": 22.24058, "count": 0, 'area_id': '12862'},
    {"lng": 113.542861, "lat": 22.279685, "count": 0, 'area_id': '12863'},
    {"lng": 113.568307, "lat": 22.370494, "count": 0, 'area_id': '12864'},
    {"lng": 113.23605, "lat": 22.230332, "count": 0, 'area_id': '12865'},
    {"lng": 113.315788, "lat": 22.233848, "count": 0, 'area_id': '12866'},
    {"lng": 113.572762, "lat": 22.28485, "count": 0, 'area_id': '12867'},
    {"lng": 113.598634, "lat": 22.24524, "count": 0, 'area_id': '12868'},
    {"lng": 113.585755, "lat": 22.262261, "count": 0, 'area_id': '12869'},
    {"lng": 113.517393, "lat": 22.230704, "count": 0, 'area_id': '12870'},
    {"lng": 113.378178, "lat": 22.007422, "count": 0, 'area_id': '12872'},
    {"lng": 113.374262, "lat": 22.081156, "count": 0, 'area_id': '12873'},
    {"lng": 113.55616, "lat": 22.221198, "count": 0, 'area_id': '12874'}
]
var heatChartData = [];*/
//热力图
var initHeatChart = function () {
    airPassengerFlow.heatChart = new AMap.Map("HeatChart", {
        resizeEnable: true,
        center: airPassengerFlow.center,
        zoom: 15
    });
    airPassengerFlow.infoWindow = new AMap.InfoWindow({
        isCustom: true,
        content: "",
        offset: new AMap.Pixel(0,-15)
    });
    if (!isSupportCanvas()) {
        alert('热力图仅对支持canvas的浏览器适用,您所使用的浏览器不能使用热力图功能,请换个浏览器试试~')
    }
    for(var a in area_path){
        var path = area_path[a];
        airPassengerFlow.heat_polygon[a] = new AMap.Polygon({
            path: path,
            isOutline: true,
            strokeColor: "#1397e4",
            strokeWeight: 2,
            strokeOpacity: 1,
            fillOpacity: 0.3,
            fillColor: '#1c9ae3',
            zIndex: 50,
        });
        airPassengerFlow.heatChart.add(airPassengerFlow.heat_polygon[a]);
        airPassengerFlow.heat_polygon[a].on("mouseover",function (event) {
            var extData = event.target.Je.extData;
            if(extData) {
                airPassengerFlow.infoWindow.setPosition(extData.position);
                airPassengerFlow.infoWindow.setContent(ContentSet(extData));
                airPassengerFlow.infoWindow.open(airPassengerFlow.heatChart, extData.position);
            }
        });
        airPassengerFlow.heat_polygon[a].on("mouseout",function (event) {
            airPassengerFlow.heatChart.remove(airPassengerFlow.infoWindow);
        });
    }
    /*airPassengerFlow.heatChart.plugin(["AMap.Heatmap"], function() {
        //初始化heatmap对象
        airPassengerFlow.heatMap = new AMap.Heatmap(airPassengerFlow.heatChart, {
            radius: 25, //给定半径
            opacity: [0, 0.8],
            gradient:{
                0.2: 'blue',
                0.4: 'rgb(117,211,248)',
                0.6: 'rgb(0, 255, 0)',
                0.8: '#ffea00',
                1.0: 'red'
            }
        });
        /*
        for(var a in HeatChartAreaName){
            var path = HeatChartAreaName[a].path;
            airPassengerFlow.heat_polygon[a] = new AMap.Polygon({
                path: path,
                isOutline: true,
                strokeColor: "#1397e4",
                strokeWeight: 2,
                strokeOpacity: 1,
                fillOpacity: 0.3,
                fillColor: '#1c9ae3',
                zIndex: 50,
            });
            airPassengerFlow.heat_polygon[a].setMap(airPassengerFlow.heatChart);
            airPassengerFlow.heat_polygon[a].on("mouseover",function (event) {
                var extData = event.target.Je.extData;
                console.log(extData);
                if(extData) {
                    airPassengerFlow.infoWindow.setPosition(extData.position);
                    airPassengerFlow.infoWindow.setContent(ContentSet(extData));
                    airPassengerFlow.infoWindow.open(airPassengerFlow.heatChart, extData.position);
                }
            });
            airPassengerFlow.heat_polygon[a].on("mouseout",function (event) {
                airPassengerFlow.heatChart.remove(airPassengerFlow.infoWindow);
            });
        }

        initHeatChartData();
        /*
        for(var i in airPassengerFlow.heat_marker){
            airPassengerFlow.heat_marker[i].on("mouseover",function (event) {
                // console.log(event);
                var extData = event.target.Je.extData;
                airPassengerFlow.infoWindow.setPosition(extData.position);
                airPassengerFlow.infoWindow.setContent(ContentSet(extData));
                airPassengerFlow.infoWindow.open(airPassengerFlow.heatChart,extData.position);
            });
            airPassengerFlow.heat_marker[i].on("mouseout",function (event) {
                airPassengerFlow.heatChart.remove(airPassengerFlow.infoWindow);
            });
        }*/
    // });
    initHeatChartData();
    setInterval(function () {
        initHeatChartData();
    },1000*60*5);
};
var initHeatChartData = function () {
    $.ajax({
        url: "getHeatData.do",
        type: "GET",
        async: false,
        success: function (result) {
            var leastHeatData = result.data;
            for(var a in HeatChartName){
                var opt = { fillColor: 'blue'};
                airPassengerFlow.heat_polygon[HeatChartName[a]].setOptions(opt);
                var data = {areaId:a,userCount:0,position:area_path[HeatChartName[a]][0]}
                airPassengerFlow.heat_polygon[HeatChartName[a]].setExtData(data);
            }
            for(var l in leastHeatData){
                var data = leastHeatData[l];
                if(HeatChartName[data.areaId]){
                    var opt = { fillColor: 'blue'};
                    if(data.userCount) {
                        if (data.userCount < 200) {
                            opt = {
                                strokeColor: '#1397e4',
                                fillColor: '#1c9ae3'
                            };
                        } else if (data.userCount <  500) {
                            opt = {
                                strokeColor: '#28bb20',
                                fillColor: '#37d82f'
                            };
                        } else if (data.userCount < 1000) {
                            opt = {
                                strokeColor: '#f39700',
                                fillColor: '#f39700'
                            };
                        } else {
                            opt = {
                                strokeColor: '#ef5151',
                                fillColor: '#ef5151'
                            };
                        }
                    }
                    data.position = area_path[HeatChartName[data.areaId]][0];
                    airPassengerFlow.heat_polygon[HeatChartName[data.areaId]].setOptions(opt);
                    airPassengerFlow.heat_polygon[HeatChartName[data.areaId]].setExtData(data);
                }
            }
        }
    })
}
// var initHeatChartData = function(){
//     $.ajax({
//         url:"getHeatData.do",
//         type:"GET",
//         async:false,
//         success:function (result) {
//             // HeatChart = [];
//             var leastHeatData = result.data;
//             for(var l in leastHeatData){
//                 var data = leastHeatData[l];
//                 if(HeatChartAreaName[data.areaId]){
//                     var opt = { fillColor: 'blue'};
//                     if(data.userCount) {
//                         if (data.userCount < 200) {
//                             opt = {
//                                 strokeColor: '#1397e4',
//                                 fillColor: '#1c9ae3'
//                             };
//                         } else if (data.userCount <  500) {
//                             opt = {
//                                 strokeColor: '#28bb20',
//                                 fillColor: '#37d82f'
//                             };
//                         } else if (data.userCount < 1000) {
//                             opt = {
//                                 strokeColor: '#f39700',
//                                 fillColor: '#f39700'
//                             };
//                         } else {
//                             opt = {
//                                 strokeColor: '#ef5151',
//                                 fillColor: '#ef5151'
//                             };
//                         }
//                     }
//                     data.position = HeatChartAreaName[data.areaId].path[0];
//                     airPassengerFlow.heat_polygon[data.areaId].setOptions(opt);
//                     airPassengerFlow.heat_polygon[data.areaId].setExtData(data);
//                 }
//             }
//             /*
//             for (var l in leastHeatData) {
//                 var data = leastHeatData[l];
//                 if (HeatChartName[data.areaId]) {
//                     HeatChart.push({
//                         "lng": HeatChartName[data.areaId].lon,
//                         "lat": HeatChartName[data.areaId].lat,
//                         "count": data.userCount
//                     });
//                     if (!airPassengerFlow.heat_marker[data.areaId]) {
//                         data.position = [HeatChartName[data.areaId].lon, HeatChartName[data.areaId].lat];
//                         var marker = new AMap.Marker({
//                             position: [HeatChartName[data.areaId].lon, HeatChartName[data.areaId].lat],
//                             offset: new AMap.Pixel(-20, -20),
//                             icon: 'images/touming.png',
//                             extData: data
//                         });
//                         marker.setMap(airPassengerFlow.heatChart);
//                         airPassengerFlow.heat_marker[data.areaId] = marker;
//                     } else {
//                         airPassengerFlow.heat_marker[data.areaId].setExtData(data);
//                     }
//                 }
//             }
//             var a = [];
//             for(var b in HeatChart){
//                 a.push(HeatChart[b]);
//             }
//             airPassengerFlow.heatMap.setDataSet({
//                 data: a,
//                 max: 10000
//             });*/
//         }
//     })
// };

// 热力图浮窗内容
function ContentSet(data) {
    var content = '<div class="chart-tip">' +
            '<span>'+getAreaName(data.areaId)+'</span>'+
            '<p>'+data.userCount+'人</p>'+
            '</div>';
    return content;
}

function getAreaName(areaId) {
    if(HeatChartName[areaId]){
        return HeatChartName[areaId];
    }
}

//判断浏览区是否支持canvas
function isSupportCanvas() {
    var elem = document.createElement('canvas');
    return !!(elem.getContext && elem.getContext('2d'));
}

// 图表自适应浏览器尺寸
window.onresize = function () {
    airPassengerFlow.flowChart.resize();
    airPassengerFlow.positionChart.resize();
};